package com.woniu.user.service.impl;

import com.woniu.order.feign.OrderFeignClient;
import com.woniu.order.pojo.Order;
import com.woniu.user.pojo.UserComments;
import com.woniu.user.mapper.UserCommentsMapper;
import com.woniu.user.service.IUserCommentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lydia
 * @since 2023-02-22
 */
@Service
public class UserCommentsServiceImpl extends ServiceImpl<UserCommentsMapper, UserComments> implements IUserCommentsService {

    @Autowired
    private OrderFeignClient orderFeignClient;
    @Resource
    private UserCommentsMapper userCommentsMapper;

    @Override
    public int addComment(String orderNo, String username, String content) {
        Order order = orderFeignClient.selectOrderByOrderNOAndUsername(orderNo, username).getData();
        UserComments userComments = new UserComments();
        userComments.setContent(content);
        userComments.setCreatedTime(new Date());
        userComments.setUpdatedTime(new Date());
        userComments.setOrderId(order.getId());
        userComments.setOrderNo(orderNo);
        userComments.setUserId(order.getUserId());
        userComments.setUsername(username);
        int insert = userCommentsMapper.insert(userComments);
        return insert;
    }
}
